define(["jquery", "easy-admin"], function ($, ea) {
    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return decodeURI(pair[1]);  //处理中文显示异常
            }
        }
    }
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'mall.withdraw_record/index',
        withdraw_url: 'mall.withdraw_record/withdraw',
        export_url: 'mall.withdraw_record/export',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh'],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '用户ID', search: false},
                    {field: 'name', title: '姓名'},
                    {field: 'mobile', title: '电话号码'},
                    {field: 'avatar_url', title: '头像', templet: ea.table.image, search: false},
                    {field: 'balance', title: '余额', templet: ea.table.price},
                    {field: 'withdraw_amount_done', title: '已提现', templet: ea.table.price, search: false},
                    {field: 'withdraw_amount_in', title: '提现审核中', templet: ea.table.price, search: false},
                    {field: 'failure_subsidy_amount', title: '补贴金额', templet: ea.table.price, search: false},
                    {
                        width: 250, title: '操作', templet: ea.table.tool, operat: [
                            [{
                                text: '明细',
                                url: init.withdraw_url,
                                method: 'open',
                                auth: 'withdraw',
                                class: 'layui-btn layui-btn-normal layui-btn-xs',
                            }]

                        ]
                    },
                ]],
            });

            ea.listen();
        },
        withdraw: function () {
            ea.table.render({
                elem: '#withdrawTable',
                url: 'withdraw',
                where: {id: getQueryVariable('id')},
                init: init,
                toolbar: [
                    'refresh'
                ],
                cols: [[
                    // {type: 'checkbox'},
                    {field: 'id', title: 'id', search: false},
                    {field: 'amount', title: '提现金额', templet: ea.table.price, search: false},
                    {
                        field: 'status',
                        width: 150,
                        title: '状态',
                        selectList: {0: '审核中', 1: '打款中', 2: '提现成功', 3: '奖励金额', 10: '提现被驳回'}
                    },
                    {field: 'balance', width: 150, title: '变动后余额', templet: ea.table.price, search: false},
                    {field: 'create_time', minWidth: 80, title: '创建时间', search: 'range'},
                ]],
            });

            ea.listen();
        },
    };
    return Controller;
});